package icu.javacg.storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import icu.javacg.storage.pojo.FireEquipment;
import icu.javacg.storage.pojo.vo.DataTableResults;
import icu.javacg.storage.pojo.vo.ReturnResult;
import icu.javacg.storage.service.FireEquipmentService;
import icu.javacg.storage.mapper.FireEquipmentMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
* @author sky
* @description 针对表【fire_equipment(消防器材表)】的数据库操作Service实现
* @createDate 2023-04-25 08:42:50
*/
@Service
public class FireEquipmentServiceImpl extends ServiceImpl<FireEquipmentMapper, FireEquipment>
    implements FireEquipmentService{

    @Resource
    FireEquipmentMapper fireEquipmentMapper;
    @Override
    public DataTableResults selectPermissionListPage(int start, int length, String orderField, String orderDir) {
            DataTableResults results = new DataTableResults();
            Page<FireEquipment> page = new Page<>(start, length);
            QueryWrapper<FireEquipment> query = new QueryWrapper<>();
            if (StringUtils.hasText(orderDir) && StringUtils.hasText(orderField)){
                if (orderDir.equals("ASC")){
                    query.orderByAsc(orderField);
                }else {
                    query.orderByDesc(orderField);
                }
            }
            Page<FireEquipment> permissionPage = fireEquipmentMapper.selectPage(page, query);
            results.setRecordsTotal(permissionPage.getTotal());
            results.setData(permissionPage.getRecords());
            results.setRecordsFiltered(permissionPage.getCurrent());
            return results;
        }

    @Override
    public ReturnResult<FireEquipment> addFire(FireEquipment fireEquipment) {
         boolean insert = fireEquipmentMapper.insert(fireEquipment) > 0;
         if (insert){
             return new ReturnResult<>(2540,"添加成功");
         }
            return new ReturnResult<>(2040,"添加失败");

    }




}




